﻿using FakeXieCheng1.API.Models;
using JXC.Core.Models;
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
//using System.Data.Entity;
using System.Linq;

using System.Text;
using System.Threading.Tasks;

namespace JXC.EFCore
{
    public class AppDbContext : DbContext
    {
        public AppDbContext(DbContextOptions<AppDbContext> options)
            : base(options)
        {


        }
        public DbSet<GoodsType> GoodsType { get; set; }
        public DbSet<AuditLogging> AuditLogging { get; set; }
        public DbSet<Alarm> Alarm { get; set; }
        public DbSet<Alarminfo> Alarminfo { get; set; }
        public DbSet<CaigouDuepay> CaigouDuepay { get; set; }
        public DbSet<CaigouEnter> CaigouEnter { get; set; }
        public DbSet<CaigouOrder> CaigouOrder { get; set; }
        public DbSet<CaigouPaid> CaigouPaid { get; set; }
        public DbSet<CaigouPlan> CaigouPlan { get; set; }
        public DbSet<CaigouReturned> CaigouReturned { get; set; }
        public DbSet<CaigouStorageDetails> CaigouStorageDetails { get; set; }
        public DbSet<Cinfo> Cinfo { get; set; }
        public DbSet<CommodityInformationSheet> CommodityInformationSheet { get; set; }
        public DbSet<DeliveryOrderDetails> DeliveryOrderDetails { get; set; }
        public DbSet<DetailsOfTheReceipt> DetailsOfTheReceipt { get; set; }
        public DbSet<Employee> Employee { get; set; }
        public DbSet<GoodsReturnedNote> GoodsReturnedNote { get; set; }
        public DbSet<Inrd> Inrd { get; set; }
        public DbSet<Inregister> Inregister { get; set; }
        //public DbSet<InventoryFile> InventoryFile { get; set; }
        public DbSet<MenuInfos> MenuInfos { get; set; }
        public DbSet<NventoryFile> NventoryFile { get; set; }
        public DbSet<Order> Order { get; set; }
        public DbSet<CaiGouOrderDetail> CaiGouOrderDetails { get; set; }
        public DbSet<OrderDetails> OrderDetails { get; set; }
        public DbSet<OutboundDeliveryOrder> OutboundDeliveryOrder { get; set; }
        public DbSet<PaidDetail> PaidDetail { get; set; }
        public DbSet<PlanDetail> PlanDetail { get; set; }
        public DbSet<Quotation> Quotation { get; set; }
        public DbSet<QuotationSheetDetails> QuotationSheetDetails { get; set; }
        public DbSet<Receipt> Receipt { get; set; }
        public DbSet<ReturnedDetail> ReturnedDetail { get; set; }
        public DbSet<ReturnList> ReturnList { get; set; }
        public DbSet<RoleInfos> RoleInfos { get; set; }
        public DbSet<RoleMenuInfos> RoleMenuInfos { get; set; }
        public DbSet<ShouldBeOfVoucher> ShouldBeOfVoucher { get; set; }
        public DbSet<Supplier> Supplier { get; set; }
        public DbSet<TheCustomerTable> TheCustomerTable { get; set; }
        public DbSet<UserRoleInfos> UserRoleInfos { get; set; }
        public DbSet<UserInfos> UserInfos { get; set; }
        //public DbSet<TouristRoute> TouristRoute { get; set; }
        //public DbSet<TouristRoutePicture> TouristRoutePicture { get; set; }


        protected override void OnModelCreating(ModelBuilder modelBuilder)
        {
            modelBuilder.Seed();
            //modelBuilder.Entity<CaigouOrder>().HasMany().WithRequired(p => p.Company).WillCascadeOnDelete(false)
            modelBuilder.Entity<CaigouOrder>().HasOne(l => l.Examiner)
                .WithMany(l => l.ExaminersGouOrder)
                .HasForeignKey(l => l.ExaminerID)
                .OnDelete(DeleteBehavior.ClientSetNull);
            modelBuilder.Entity<CaigouOrder>().HasOne(l => l.Operator)
                .WithMany(l => l.OperatorsCaiGouOrder)
                .HasForeignKey(l => l.OperatorID)
                .OnDelete(DeleteBehavior.NoAction);

            //modelBuilder.Entity<CaigouEnter>().HasOne(l => l.Buyer)
            //    .WithMany(p => p.CaigouEntersPurchasingAgent)
            //    .HasForeignKey(p => p.BuyerID).OnDelete(DeleteBehavior.NoAction);

            modelBuilder.Entity<CaigouEnter>().HasOne(l => l.Examiner)
              .WithMany(p => p.CaigouEntersExaminer)
              .HasForeignKey(p => p.ExaminerID).OnDelete(DeleteBehavior.NoAction);

            modelBuilder.Entity<CaigouEnter>().HasOne(l => l.Opmanl)
              .WithMany(p => p.CaigouEntersOpmanl)
              .HasForeignKey(p => p.OpmanlID).OnDelete(DeleteBehavior.NoAction);

            modelBuilder.Entity<CaigouEnter>().HasOne(l => l.Operator)
              .WithMany(p => p.CaigouEntersOperator)
              .HasForeignKey(p => p.OperatorID).OnDelete(DeleteBehavior.NoAction);

            modelBuilder.Entity<CaigouReturned>().HasOne(l => l.Operator).WithMany(p => p.CaigouReturnedsOperator)
                .HasForeignKey(p => p.OperatorID).OnDelete(DeleteBehavior.NoAction);
            modelBuilder.Entity<CaigouReturned>().HasOne(l => l.Examiner).WithMany(p => p.CaigouReturnedsExaminer)
               .HasForeignKey(p => p.ExaminerID).OnDelete(DeleteBehavior.NoAction);
            modelBuilder.Entity<CaigouReturned>().HasOne(l => l.Shipper).WithMany(p => p.CaigouReturnedsShipper)
             .HasForeignKey(p => p.ShipperID).OnDelete(DeleteBehavior.NoAction);

            modelBuilder.Entity<CaigouDuepay>().HasOne(l => l.Operaror).WithMany(p => p.CaigouDuepaysOperator)
                .HasForeignKey(p => p.OperarorID).OnDelete(DeleteBehavior.NoAction);
            modelBuilder.Entity<CaigouDuepay>().HasOne(l => l.Examiner).WithMany(p => p.CaigouDuepaysExaminer).HasForeignKey(p => p.ExaminerID)
                .OnDelete(DeleteBehavior.NoAction);

            modelBuilder.Entity<CaigouPaid>().HasOne(l => l.Operator).WithMany(p => p.CaigouPaidsOperator).HasForeignKey(p => p.OperatorID)
                .OnDelete(DeleteBehavior.NoAction);
            modelBuilder.Entity<CaigouPaid>().HasOne(l => l.Examiner).WithMany(p => p.CaigouPaidsExaminer).HasForeignKey(p => p.ExaminerID)
                .OnDelete(DeleteBehavior.NoAction);
            modelBuilder.Entity<PaidDetail>().HasOne(l => l.CaigouOrder).WithMany(p => p.PaidDetails).HasForeignKey(p => p.CaigouOrderId)
                .OnDelete(DeleteBehavior.NoAction);
            



            //modelBuilder.Entity<CaigouEnter>().HasOne(l => l.CaigouOrder)
            //    .WithMany(p => p.CaigouEnters)
            //    .HasForeignKey(p => p.CaiGouOrderID).OnDelete(DeleteBehavior.NoAction);

            //modelBuilder.Entity<CaigouEnter>().HasOne(l => l.Supplier)
            //    .WithMany(p => p.CaigouEnters).HasForeignKey(p => p.SupplierId).OnDelete(DeleteBehavior.NoAction);


        }


    }
}
